/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;
import mensch.Player;
import org.apache.log4j.Logger;

/**
 *
 * @author robert
 */
@ManagedBean(name = "loginController")
@SessionScoped
public class Login implements Serializable {

    public Login() {
    }
    private final static Logger LOG = Logger.getLogger(Login.class.getName());
    @ManagedProperty(value = "#{player}")
    private Player loginPlayer;
    @ManagedProperty(value = "#{registeredPlayers}")
    private RegisteredPlayers registeredPlayers;
    @ManagedProperty(value = "true")
    private boolean loginSuccess;
    private String username;
    private String password;

    public String login() {
        loginPlayer = registeredPlayers.getRegisteredPlayer(username);

        if (loginPlayer != null && loginPlayer.getPassword().equals(password)) {
            LOG.info("Player ungleich null, Passwort korrekt, gehe zum Table");
            loginSuccess = true;

            LOG.info("Folgender Spieler soll weitergereicht werden: " + loginPlayer.getUsername());
            //           gameBean = new MenschBean(new Player(loginPlayer.getUsername(),0));

            return "table";
        } else {
            loginSuccess = false;
        }

        return "index";
    }

    public Player getLoginPlayer() {
        return loginPlayer;
    }

    public void setLoginPlayer(Player loginPlayer) {
        this.loginPlayer = loginPlayer;
    }

    public boolean isLoginSuccess() {
        return loginSuccess;
    }

    public void setLoginSuccess(boolean loginSuccess) {
        this.loginSuccess = loginSuccess;
    }

    public RegisteredPlayers getRegisteredPlayers() {
        return registeredPlayers;
    }

    public void setRegisteredPlayers(RegisteredPlayers registeredPlayers) {
        this.registeredPlayers = registeredPlayers;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    /*
     * public MenschBean getGameBean() { return gameBean; }
     *
     * public void setGameBean(MenschBean gameBean) { this.gameBean = gameBean;
    }
     */
}
